#include <iostream>
#include <string.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "dirent.h"
#include <time.h>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
using namespace std;

//读取某给定路径下所有文件夹与文件名称，并带完整路径
static void getAllFilesInDirs(string path, vector<string> &filePath)
{
    DIR *pDir;
    struct dirent *ptr;
    if (!(pDir = opendir(path.c_str())))
        return;
    while ((ptr = readdir(pDir)) != 0)
    {
        filePath.push_back(ptr->d_name);
    }
    closedir(pDir);
}

struct annatation_diy
{
    int _id;
    string _class;
    vector<float> _2d_bbox;
    vector<float> _3d_bbox;
    float _yaw;
};

int main()
{
    string path = "/home/zwh/lidar_annotation/_bbox/";
    vector<string> filePath;
    getAllFilesInDirs(path, filePath);
    for (size_t i = 0; i < filePath.size(); i++)
    {
        std::ifstream infile(path + filePath[i]);
        std::string line;
        std::ofstream outfile;
        outfile.open(path + "../anna/" + filePath[i]);
        while (getline(infile, line))
        {
            stringstream ss;
            ss.str(line);
            string single;
            int i = 0;
            // 按照空格分隔

            vector<string> tvecData;
            while (getline(ss, single, '\t'))
            {
                tvecData.push_back(single);
            }
            ss.clear(); //必须加，不然写不到string里。

            outfile << 1 << "\t" << tvecData[0] << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t"
                    << tvecData[2] << "\t" << tvecData[3] << "\t" << tvecData[4] << "\t" << tvecData[5] << "\t"
                    << tvecData[6] << "\t" << tvecData[7] << "\t" << stod(tvecData[9]) / 57.3 << "\n";

            // annatation_diy anna;
            // anna._id = 1;
            // anna._class = tvecData[0];
            // anna.
        }
        infile.close();
        outfile.close();
    }

    return 0;
}